package com.csu.mall.product.app;

import com.csu.mall.common.utils.PageUtils;
import com.csu.mall.common.utils.R;
import com.csu.mall.product.entity.AttrAttrgroupRelationEntity;
import com.csu.mall.product.feign.CouponFeignService;
import com.csu.mall.product.service.AttrAttrgroupRelationService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;


/**
 * 属性&属性分组关联
 *
 * @author zhenhuanli
 * @email 743879362@qq.com
 * @date 2022-09-16 11:42:54
 */
//配置中心和当前配置文件有相同的配置项，会优先读取配置中心的值
//SpringBoot读取配置文件的注解，都可以读取配置中心的值，包括@Value, @ConfigurationProperties
//@RefreshScope 可以动态读取nacos配置中心的配置项
@RefreshScope
@RestController
@RequestMapping("product/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Resource
    private AttrAttrgroupRelationService attrAttrgroupRelationService;

    @Resource
    private CouponFeignService couponFeignService;

    @Value("${name}")
    private String name;

    @Value("${age}")
    private Integer age;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrgroupRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
//		attrAttrgroupRelationService.save(attrAttrgroupRelation);
        attrAttrgroupRelationService.saveAttrAttrGroupRelationEntity(attrAttrgroupRelation);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/test")
    public String sayHello(){
        return "name: " + name +", age" + age;
    }
}
